#ifndef INC_NSCONFIG_H_
#define INC_NSCONFIG_H_

#include <string>
#include <Poco/Mutex.h>
#include <Poco/Net/SocketAddress.h>

#define DEFAULT_NET_INTERFACE "wlan0"
#define DEFAULT_MULTICAST_GROUP "239.0.0.2:4000"
#define DEFAULT_BROADCAST_FREQUENCY "5000"
#define DEFAULT_KEEPALIVE_SEND_DELAY "20000"
#define DEFAULT_KEEPALIVE_CHECK_DELAY "1000"
#define DEFAULT_KEEPALIVE_REMOVE_DELAY "60000"
/*********************************************************/
class nsConfig
{
private:
	// Members
	static nsConfig& 			pInstance;	// Only available instance of config
	static Poco::Mutex*			mutex;		// Mutual exclusion object for multithreading security
	
	// Configuration parameters
	std::string				pNetworkInterface;	// The network interface used
	Poco::Net::SocketAddress		pMulticastGroup;	// The address ( & port) of the multicast group the nameserver is going to join
	unsigned int				pBroadcastFrequency;	// The time the server waits before broadcasting it's presence again
	unsigned int				pKeepAliveTime;		// After how many seconds do we send a keepalive message to check the node/client?
	unsigned int				pKeepAliveCheck;	// How many seconds pass before we check our keep alive timers again
	unsigned int				pKeepAliveRemove;	// After how many seconds of inactivity do we remove a node/client?

	// Methods
	void writeDefaultConfig();
	bool parse();

	// Copy Construction/Assignment operator
	nsConfig();						// Constructor
	nsConfig( const nsConfig& );				// Copy Constructor
	nsConfig& operator=(const nsConfig&);			// Assignment operator

protected:
public:
	// Methods for retrieval of configuration parameters
	std::string getNetworkInterface() const;
	Poco::Net::SocketAddress getMulticastGroup() const;
	unsigned int getBroadcastFrequency() const;
	unsigned int getKeepAliveTime() const;
	unsigned int getKeepAliveCheckDelay() const;
	unsigned int getKeepAliveRemoveDelay() const;

	// Methods for setting configuration parameters
	void setNetworkInterface( const std::string& );
	void setMulticastGroup(const Poco::Net::SocketAddress&);
	void setBroadcastFrequency(const unsigned int&);
	void setKeepAliveTime(const unsigned int&);
	void setKeepAliveCheckDelay(const unsigned int&);
	void setKeepAliveRemoveDelay(const unsigned int&);

	// Methods to reinitialize ( reparsing the config.ini file )
	void reparse();

	// Construction & Destruction
	static nsConfig& Instance();				// Instance retrieval method
	virtual ~nsConfig();					// Destructor
};
/*********************************************************/
#endif // INC_CONFIG_H_
